﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QL_NOI_TRU
{
    public partial class frmNhapDMThuoc : DevExpress.XtraEditors.XtraForm
    {
        public frmNhapDMThuoc()
        {
            InitializeComponent();
        }

        private void frmNhapDMThuoc_Load(object sender, EventArgs e)
        {
            tbTenThuoc.Focus();
            var kn = new Ketnoi(frmDangnhap.stringConn);
            gridControl1.DataSource = kn.ExcuteQuery("select MATHUOC,TENTHUOC,GIA from THUOC");
        }

        private void btThemThuoc_Click(object sender, EventArgs e)
        {
                string strr = "EXEC Insert_Thuoc @TENTHUOC = '" + tbTenThuoc.Text.ToString() + "',@GIA = '" + tbGia.Text.ToString().Trim() + "'";
                var kn = new Ketnoi(frmDangnhap.stringConn);
                kn.ExcuteQuery(strr);
                btRefreshThuoc_Click(null, null);
            /*obThuoc ob = new obThuoc { MATHUOC = tbMaThuoc.Text, TENTHUOC = tbTenThuoc.Text, GIATHUOC = tbGia.Text };

            if (ob.MATHUOC != "")
            {
                string a = String.Format("Insert into THUOC VALUES('{0}',N'{1}','{2}')", ob.MATHUOC, ob.TENTHUOC, ob.GIATHUOC);
                var kn = new Ketnoi(frmDangnhap.stringConn);
                kn.ExcuteNonQuery(a);
                btRefreshThuoc_Click(null, null);
            }
            else
            {
                MessageBox.Show("chưa nhập mã thuốc!");
            }
             */
        }

        private void btRefreshThuoc_Click(object sender, EventArgs e)
        {
            tbTenThuoc.Text = "";
            tbGia.Text = "";
            frmNhapDMThuoc_Load(null, null);
        }

        private void tbTenThuoc_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                tbGia.Focus();
        }

    }
}